package com.hspedu.smallchange.oop;

import com.hspedu.smallchange.SmallChangeSys;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class SmallChangeSysOOP {
    double balance = 0;
    //定义相关变量
    boolean loop = true;
    Scanner scanner = new Scanner(System.in);
    String key = "";
    SmallChangeSys smallChangeSys = new SmallChangeSys();
    double money = 0;
    String details = " ";
    String note = "";
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");//日期格式化
    //主菜单
    public void mainMenu(){
        do{
            System.out.println("=======零钱通菜单=======");
            System.out.println("\t\t\t1 零钱通明细");
            System.out.println("\t\t\t2 收益入账");
            System.out.println("\t\t\t3 消费");
            System.out.println("\t\t\t4 退出");

            System.out.println("请选择（1-4）:");
            key = scanner.next();

            //使用switch分支控制
            switch(key){
                case "1":
                    this.detail();
                    break;
                case "2":
                    this.income();
                    break;

                case "3":
                    this.outcome();
                    break;
                case "4":
                    loop = false;
                    break;
                default:
                    System.out.println("选择有误， 请重新选择");

            }
        }while(loop);

    }

    //零钱通明细
    public void detail(){
        System.out.println(details);
    }

    //完成收益入账
    public void income(){
        System.out.println("2 收益入账");
        System.out.println("请输入入账金额：");
        while (true){
            money = scanner.nextDouble();
            if (money<=0){
                System.out.println("请输入大于0的数");
            }else{
                balance += money;
                //拼接收益入账信息
                Date date = new Date();
                details += "收益入账\t" + money + "\t" + simpleDateFormat.format(date) +"\t"+balance+"\n";
                System.out.println(details);
                break;
            }

        }
    }

    //完成消费
    public void outcome(){
        System.out.println("2 收益入账");
        System.out.println("请输入消费金额：");
        while (true){
            money = scanner.nextDouble();
            if (money<=0){
                System.out.println("请输入大于0的数");
            }else{
                balance -= money;
                //拼接收益入账信息
                Date date = new Date();
                details += "消费金额\t-" + money + "\t" + simpleDateFormat.format(date) +"\t"+balance+"\n";
                System.out.println(details);
                break;
            }

        }
    }

    public void exit(){
        System.out.println("4 退出");
    }

}
